package com.hzx.ssm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hzx.ssm.dao.NoticeDao;
import com.hzx.ssm.entity.Message;
import com.hzx.ssm.entity.Notice;
import com.hzx.ssm.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeDao noticeDao;

    @Override
    public void addNotice(Notice notice) {
        notice.setNotice_time(new Date());
        notice.setNotice_id(UUID.randomUUID().toString());
        noticeDao.addNotice(notice);

    }

    @Override
    public void deleteNoticeById(String notice_id) {
        noticeDao.deleteNoticeById(notice_id);
    }

    @Override
    public void updateNoticeById(Notice notice) {
        notice.setNotice_time(new Date());
        noticeDao.updateNoticeById(notice);

    }

    @Override
    public HashMap<String,Object> findAll(Integer pageNum,Integer sizeNum) {
        Page<Notice> page = PageHelper.startPage(pageNum, sizeNum);
        List<Notice> allNotice = noticeDao.findAll();
        int pages = page.getPages();
        HashMap<String, Object> data = new HashMap<>();
        data.put("allNotice",allNotice);
        data.put("pagesNum",pages);
        return data;
    }

    @Override
    public Notice findNoticeById(String notice_id) {
        return findNoticeById(notice_id);
    }
}
